import {defineStore } from 'pinia'
import request from '@/utils/request'
import {ApiRes,BannerItem ,newGoodsItem,hotGoodsItem,BrandItem,HomeProduct,Special} from '@/types/data'
const useHomeStore = defineStore('home',{
  state(){
    return{
      // 轮播图数据
      bannerLsit:[] as BannerItem[],
      // 新鲜好物数据
      newGoodsList:[] as newGoodsItem[],
      // 人气推荐
      hotGoodsList:[] as hotGoodsItem[],
      // 人气品牌
      brandList:[] as BrandItem[],
      // 商品主体数据
      productList:[] as HomeProduct[],
      // 专题类型数据
      specialList: [] as Special[],
    }
  },
  actions:{
    // 获取轮播图数据
    async getBannerList(){
      const res = await request.get<ApiRes<BannerItem[]>>('/home/banner')
      this.bannerLsit=res.data.result
    },
    // 获取新鲜好物数据
   async getNewGoodsList(){
      const res = await request.get<ApiRes<newGoodsItem[]>>('/home/new')
      this.newGoodsList=res.data.result
      console.log(res);
    },
    // 获取人气推荐数据
    async getHotGoodsList(){
      const res = await request.get<ApiRes<hotGoodsItem[]>>('/home/hot')
      console.log(res);
      this.hotGoodsList=res.data.result
      
    },
    // 获取人气品牌
    async getBrandList(){
      const res = await request.get<ApiRes<BrandItem[]>>('/home/brand')
      this.brandList=[
        ...res.data.result,
        ...res.data.result
      ]
    },
    // 获取商品主体数据
    async getProductList() {
      const res = await request.get<ApiRes<HomeProduct[]>>('/home/goods')
      this.productList = res.data.result
    },
    // 获取专题数据
    async getSpecialList() {
      const res = await request.get<ApiRes<Special[]>>('/home/special')
      this.specialList = res.data.result
    },
  },
  getters:{}
})
export default useHomeStore